<template>
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-md-12 col-lg-6 col-xl-6">
        <div class="card shadow-lg o-hidden border-0 my-5">
          <div class="card-body p-0">
            <div class="row align-items-center">
              <div class="col-lg-12">
                <div class="p-5">
                  <div class="text-center">
                    <h4 class="text-dark mb-4">商家登录</h4>
                  </div>
                  <div class="mb-3"><input class="form-control" v-model="ventor.vtelephone" placeholder="手机号" /></div>
                  <div class="mb-3"><input class="form-control" v-model="ventor.vpassword" type="password" placeholder="密码" name="password" /></div>
                  <button class="btn btn-primary w-100" style="margin-bottom: 10px" @click="login()">登录</button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "Login",
  data(){
    return{
      ventor:{
        vtelephone:'',
        vpassword:''
      },
    }
  },
  methods:{
    login(){
      axios.get('http://localhost:9001/ventor/ventorLogin?vtelephone='+this.ventor.vtelephone+'&vpassword='+this.ventor.vpassword).then(res=>{
        if (res.data===null) {
          this.$message.error("账号或密码错误");
        } else{
          sessionStorage.setItem("vid",res.data.vid);
          sessionStorage.setItem("sid",res.data.sid);
          sessionStorage.setItem("vname",res.data.vname);
          sessionStorage.setItem("vpassword",res.data.vpassword);
          sessionStorage.setItem("vtelephone",res.data.vtelephone);
          sessionStorage.setItem("sname",res.data.sname);
          sessionStorage.setItem("isLogin","true");
          this.$notify.success("欢迎回来,"+sessionStorage.getItem("vname"));
          this.$router.push({path:'/index/main'})
        }
      })
    },
  },
  beforeCreate() {
    if (sessionStorage.getItem("isLogin")){
      console.log(1111)
      this.$message.warning("你已经登录");
      this.$router.push({path:'/index/main'});
    }
  }
}
</script>

<style scoped>

</style>
